package cn.edu.neusoft.amicooldemo.fragment;


import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import cn.edu.neusoft.amicooldemo.CollectActivity;
import cn.edu.neusoft.amicooldemo.FocususerActivity;
import cn.edu.neusoft.amicooldemo.LoginActivity;
import cn.edu.neusoft.amicooldemo.R;


/**
 * A simple {@link Fragment} subclass.
 */
public class SettingFragment extends Fragment implements View.OnClickListener {

    private SharedPreferences sp;
    private SharedPreferences.Editor editor;
    public SettingFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View view= inflater.inflate(R.layout.fragment_setting, container, false);
        view.findViewById(R.id.btn_mycollect).setOnClickListener(this);
        view.findViewById(R.id.btn_myfocus).setOnClickListener(this);
        view.findViewById(R.id.btn_logout).setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()){

            case R.id.btn_mycollect:
                intent = new Intent(getActivity(),CollectActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_myfocus:
                intent = new Intent(getActivity(),FocususerActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_logout:
                sp = getActivity().getSharedPreferences("amicool_user", Context.MODE_PRIVATE);
                editor=sp.edit();
                editor.putString("SessionID", "");
                editor.putInt("myid",0);
                editor.putString("username", "");
                editor.putString("password", "");
                editor.commit();

                startActivity(new Intent(getActivity(),LoginActivity.class));
                getActivity().finish();
                break;
            default:

                break;
        }

    }
}
